#!/bin/bash
set -xeuo pipefail
set -o errexit

#
# USER="-u elastic-admin:elastic-password"
USER=""

# idea中设置断点
# elasticsearch/x-pack/plugin/transform/src/main/java 这里是对应的代码
# 执行这个时，preview的对应代码即可调试
echo "transforms preview..."
curl ${USER} -X POST "localhost:9200/_transform/_preview?pretty" -H 'Content-Type: application/json' -d'
{
  "source": {
    "index": [
      "aggt"
    ]
  },
  "dest" : { 
    "index" : "aggt_t"
  },
  "pivot": {
    "group_by": {
      "clientip": {
        "terms": {
          "field": "clientip"
        }
      },
      "port": {
        "histogram": {
          "field": "port",
          "interval": "1"
        }
      }
    },
    "aggregations": {
      "tm.value_count": {
        "value_count": {
          "field": "tm"
        }
      }
    }
  }
}
'
